package com.ojoin.trade.t0loan_core.web.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ojoin.trade.common.utils.TimeUtils;
import com.ojoin.trade.common.web.quartz.CronExpression;
import com.ojoin.trade.common.web.quartz.TaskGroup;
import com.ojoin.trade.common.web.task.BaseQuartzJob;
import com.ojoin.trade.t0loan_core.web.service.FtpFileBaseService;
import com.ojoin.trade.t0loan_core.web.service.T0LoanBaseService;


/**
 * @author guoting
 *
 * 配置参考spring-config-task.xml
 */
@Component
public class TxLoanTask extends BaseQuartzJob{
	
	@Autowired
	private FtpFileBaseService ftpservice;
	
	@Autowired
	private T0LoanBaseService t0loanservice;

	public FtpFileBaseService getFtpservice() {
		return ftpservice;
	}
	
	private static final Logger log = LoggerFactory
			.getLogger(TxLoanTask.class);

	//每日12-14点的10分开始，每10分钟运行1次
	@CronExpression(cron="0 10/10 10-14 * * ? ",desc="pos交易文件下载并处理",isConcurrent=false)
    public void autoExecDealFtpFile() {
    	log.info("pos交易文件下载并处理线程启动, 时间->" + TimeUtils.getCurDateTime());
		getFtpservice().saveDealAllFtpFile("txcredit");
    	log.info("pos交易文件下载并处理线程结束, 时间->" + TimeUtils.getCurDateTime());
    }
	

	//每日9-23点的每10分钟运行1次
    @CronExpression(cron="0 0/10 09-23 * * ? *",desc="Tx还款-生成任务并执行",isConcurrent=false)
    public void genTxRefundTask(){
    	log.info("Tx生成还款任务并执行还款线程启动, 时间->" + TimeUtils.getCurDateTime());
    	t0loanservice.updateGenRefundTask();
    	t0loanservice.execRunRefundTask();
    	log.info("Tx生成还款任务并执行还款线程结束, 时间->" + TimeUtils.getCurDateTime());
    }
    
//	//每日9-23点的每10分钟运行1次
//    @CronExpression(cron="0 0/10 09-23 * * ? *",desc="测试Tx还款-生成任务并执行",isConcurrent=false)
//    public void testTxRefundTask(){
//    	log.info("测试Tx生成还款任务并执行还款线程启动, 时间->" + TimeUtils.getCurDateTime());
//    	t0loanservice.testRunRefundTask();
//    	log.info("测试Tx生成还款任务并执行还款线程结束, 时间->" + TimeUtils.getCurDateTime());
//    }
    
    
    /**
	 * @param args
	 */
	public static void main(String[] args) {
			new TxLoanTask().autoExecDealFtpFile();
	}

	@Override
	public TaskGroup getTaskGroupName() {
		return TaskGroup.TxLOAN;
	}

}
